import config from "@/config/index.js";
const urlhsls = [
	// "/CdzfwfInfoSearch",
	// "/CdzstationpicSearch"
	// "/YyfglinfoSearch",
	// "/YyfglinfoAdd",
	// "/YyfglinfoEdt",
	// "/YyfglinfoDel",
	// "/CarConfigPpInfoSearch",
	// "/CarmanageinfoEdt",
	// "/CarConfigPpInfoAdd",
	// "/CarConfigPpInfoEdt",
	// "/CarConfigCxInfoSearch",
	// "/CarConfigCxInfoAdd",
	// "/CarConfigCxInfoEdt",
	// "/CarConfigZlInfoSearch",
	// "/CarConfigJtpzInfoAdd",
	// "/CarConfigJtpzInfoEdt",
	// "/CdzsbpzglinfoSearch",
	// "/CarmanageinfoSearch",
	// "/CarmanageinfoAdd",
];
export default async function() {
	let promise, callback;
	promise = new Promise((resolve, reject) => {
		callback = function(resolvedata, rejectdata) {
			if (resolvedata) {
				resolve(resolvedata);
			} else {
				reject(rejectdata);
			}
		};
	});
	let reqdata = {
		method: "POST",
		dataType: "json",
		header: {
			"Content-Type": config.contentType, //自定义请求头信息
		},
		success: (res) => {
			// console.log(res.data);
			if (reqdata.url == config.baseURL + "/StationCar") {
				res.data = res.data.filter(e => {
					return !(e.carjlsum == 0 && e.carzlsum == 0)
				})
			}
			callback(res.data)
		},
		fail: (err) => {
			console.error(err);
			callback(false, res.data)
		},
	};
	if (arguments.length == 0) {
		return [];
	}
	if (typeof arguments[0] == "object") {
		reqdata = {
			...reqdata,
			...arguments[0],
		};
	} else {
		let url = arguments[0];
		let data = arguments[1] || {};
		if (urlhsls.includes(url)) {
			url = `http://192.168.3.10:8082/SalesTankWeb` + url;
		}
		reqdata.url = url;
		reqdata.data = data;
	}

	reqdata.url = reqdata.url.includes("http") || uni.$u.test.url(reqdata.url) ?
		reqdata.url :
		config.baseURL + reqdata.url;

	uni.request(reqdata);

	return promise;
}